package engine;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

public class TableResults extends AbstractTableModel {
    
    private final List<ResultEntry> rows = new ArrayList<ResultEntry>();
    private final String[] headers = {"Similarité", "Fichier"};
    
    public TableResults() {
        super();
    }
    
    @Override
    public int getRowCount() {
        return rows.size();
    }
    
    @Override
    public int getColumnCount() {
        return headers.length;
    }
    
    @Override
    public String getColumnName(int columnIndex) {
        return headers[columnIndex];
    }
    
    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
                return rows.get(rowIndex).getScore();
            case 1:
                return rows.get(rowIndex).getFilePath().replace(rows.get(rowIndex).getCorpusPath(), "<corpusPath>");            
            default:
                return null; //Ne devrait jamais arriver
        }
    }
    
    public ResultEntry getResultAt(int rowIndex) {
        return rows.get(rowIndex);
    }
    
    public void addRow(ResultEntry row) {
        rows.add(row);
        
        fireTableRowsInserted(rows.size() - 1, rows.size() - 1);
    }
    
    public void removeRow(int rowIndex) {
        rows.remove(rowIndex);
        
        fireTableRowsDeleted(rowIndex, rowIndex);
    }
    
    public void clear(){
        rows.clear();
    }
}
